package com.itheima.controller;

import com.github.pagehelper.Page;
import com.itheima.entity.PageResult;
import com.itheima.entity.Result;
import com.itheima.pojo.ExceptionLog;
import com.itheima.pojo.PictureSort;
import com.itheima.service.PictureSortService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("/pictureSort")
public class PictureSortController {

    @Autowired
    private PictureSortService pictureSortService;

    /**
     * 增
     *
     * @param pictureSortVO
     * @return
     */
    @PostMapping("/add")
    public Result add(@RequestBody Map pictureSortVO) {
        pictureSortService.add(pictureSortVO);
        return new Result("success", "插入成功");
    }

    /**
     * 改
     *
     * @param pictureSortVO
     * @return
     */
    @PostMapping("/edit")
    public Result edit(@RequestBody Map pictureSortVO) {
        pictureSortService.edit(pictureSortVO);
        return new Result("success", "编辑成功");
    }

    /**
     * 删
     *
     * @param pictureSortVO
     * @return
     */
    @PostMapping("/delete")
    public Result delete(@RequestBody Map pictureSortVO) {
        pictureSortService.delete(pictureSortVO);
        return new Result("success", "删除成功");
    }

    /**
     * 查询所有
     *
     * @param pictureSortVO
     * @return
     */
    @PostMapping("/getList")
    public Result getList(@RequestBody Map pictureSortVO) {
        PageResult<PictureSort> pageResult = pictureSortService.getList(pictureSortVO);
        return new Result("success", pageResult);
    }

    /**
     * 根据id查询
     */
    @PostMapping("/getPictureSortByUid")
    public Result getPictureSortByUid(@RequestBody Map pictureSortVO) {
        PictureSort pictureSort = pictureSortService.getPictureSortByUid(pictureSortVO);
        return new Result("success", pictureSort);
    }

    /**
     * 置顶
     */
    @PostMapping("/stick")
    public Result stick(@RequestBody Map pictureSortVO) {
        pictureSortService.stick(pictureSortVO);
        return new Result("success", "置顶成功");
    }
}
